<extend name="Public:base"/>

<block name="main">
<div id="yzh-content">
    <div class="main-title">
        <h2>邮箱设置</h2>
    </div>
    <form id="myform" class="form-horizontal" method='post' action="{:U('Config/dosite')}">
        <div class="form-group">
            <label class="control-label col-md-2">邮件发送模式</label>
            <div class="col-md-5">
                <input name="mail_type"   value="1" onclick="showsmtp(this)" type="radio"  <if condition="$mail_type == 1">  checked</if>> {:L('config_mail_smtp')}
                <input name="mail_type"  value="2" onclick="showsmtp(this)" type="radio"  <if condition="$mail_type == 2">  checked</if>  <?php if(substr(strtolower(PHP_OS), 0, 3) == 'win') echo 'disabled'; ?>/> {:L('config_mail_mailfun')}
                <input name="mail_type"   value="3" onclick="showsmtp(this)" type="radio"  <if condition="$mail_type == 3">  checked</if>> sendmail
            </div>
        </div>

        <div id="smtpconfig" style="">
            <div class="form-group">
                <label class="control-label col-md-2">邮件服务器</label>
                <div class="col-md-5">
                    <input type="text" class="form-control" name="mail_server" id="mail_server" value="{$mail_server}"/>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-2">邮件发送端口</label>
                <div class="col-md-5">
                <input type="text" class="form-control" name="mail_port" id="mail_port" value="{$mail_port}"/>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-2">发件人地址</label>
                <div class="col-md-5">
                <input type="text" class="form-control" name="mail_from" id="mail_from" value="{$mail_from}"/>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-2">AUTH LOGIN验证</label>
                <div class="col-md-5">
                <input name="mail_auth" id="mail_auth" value="1" type="radio" <if condition="$mail_auth == 1">  checked</if>> 开启
                <input name="mail_auth" id="mail_auth" value="0" type="radio" <if condition="$mail_auth == 0">  checked</if> > 关闭
                </div>
            </div>

            <div class="form-group">
                <label class="control-label col-md-2">验证用户名</label>
                <div class="col-md-5">
                    <input type="text" class="form-control" name="mail_user" id="mail_user" value="{$mail_user}"/>
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-md-2">验证密码</label>
                <div class="col-md-5">
                    <input type="password" class="form-control" name="mail_password" id="mail_password" value="{$mail_password}"/>
                </div>
            </div>
        </div>

        <div id="sendmailconfig">
            <div class="form-group">
                <label class="control-label col-md-2">{:L('config_mail_sendmail')}</label>
                <div class="col-md-5">
                    <input type="text" class="form-control" name="mail_sendmail" id="mail_sendmail" value="{$mail_sendmail}"/>
                </div>
            </div>
        </div>

        <div class="form-group">
            <label class="control-label col-md-2">邮件设置测试</label>
            <div class="col-md-5">
                <input type="text" class="form-control w-300 pull-left" name="mail_to" id="mail_to" value=""/>
                <input type="button" class="btn btn-sm btn-primary pull-left" onClick="javascript:test_mail();" value="测试发送">
            </div>
        </div>

        <div class="form-actions">
            <input type="submit" value="保存" class="btn btn-sm btn-primary">
            <input type="reset" value="重置" class="btn btn-sm btn-primary">
        </div>
    </form>
</div>

<script>
function showsmtp(obj){

    if(obj){
        var issmtp = $(obj).val();
    }else{
        var issmtp = $("input[name=mail_type][checked]").val();
    }

    if(issmtp==1){
        $('#smtpconfig').show();
        $('#sendmailconfig').hide();
    }else if(issmtp==3){
        $('#smtpconfig').hide();
        $('#sendmailconfig').show();
    }else{
        $('#smtpconfig').hide();
        $('#sendmailconfig').hide();
    }
}
function test_mail(){

    var mail_type =  $("input[name=mail_type][checked]").val();

    $.post(
        '{:U("Config/testmail")}&mail_to='+$('#mail_to').val(),
        {mail_type:mail_type,mail_sendmail:$('#mail_sendmail').val(),
        mail_server:$('#mail_server').val(),
        mail_port:$('#mail_port').val(),
        mail_user:$('#mail_user').val(),
        mail_password:$('#mail_password').val(),
        mail_auth:$('#mail_auth').val(),
        mail_from:$('#mail_from').val()},
        function(data){
            alert(data.info);
        },"json");

}
showsmtp();
</script>

<script type="text/javascript">
$(document).ready(function() {
    $('#myform').ajaxForm({
        success:  complete,  // post-submit callback
        dataType: 'json'
    });
});

function complete(data){
    if(data.status==1){
        $.scojs_message('修改成功', $.scojs_message.TYPE_OK);
        setTimeout(function(){
            window.location.href = '{:U("Config/mail")}';
        },1000);
    }else{
        $.scojs_message(data.info, $.scojs_message.TYPE_ERROR);
    }

}
</script>
</block>